//- Copyright (c) 2016 Lucky Byte, Inc.
extends trstat

append form_items
  .field.two.wide
    .ui.labeled.dropdown.selection.input
      input(type="hidden" name="status" value="#{status || ''}")
      i.icon.dropdown
      .default.text 所有状态
      .menu
        .item(data-value="") 所有状态
        .item(data-value="1") 尚未代付
        .item(data-value="2") 等待确认
        .item(data-value="3") 代付失败
        .item(data-value="4") 代付成功
  .field.seven.wide
    .ui.buttons.right.floated.small.compact
      button.ui.green.button.labeled.icon(type="submit") 查 询
        i.icon.search
      if page_perms.export
        button.ui.red.button.right.labeled.icon(type="button"
          onclick="window.location = '/trstat/p1_order/export" +
            "?start_date=#{start_date}&end_date=#{end_date}&status=#{status}'") 下 载
          i.icon.download
      else
        button.ui.red.button.right.labeled.icon.disabled(type="button") 下 载
          i.icon.ban

block thead
  tr
    th.collapsing.center.aligned(rowspan="2") 序号
    th.collapsing.center.aligned(rowspan="2") 状态
    th.collapsing.center.aligned(rowspan="2") 交易时间
    th.collapsing.center.aligned(colspan="4") 消费交易
    th.collapsing.center.aligned(rowspan="2") 手续费
    th.collapsing.center.aligned(colspan="5") 代付交易
    th.collapsing.center.aligned(rowspan="2") 追付
  tr
    th.collapsing.center.aligned 商户编号
    th.collapsing.center.aligned 终端编号
    th.collapsing.center.aligned 跟踪号
    th.collapsing.center.aligned 交易金额
    th.collapsing.center.aligned 代付商户
    th.collapsing.center.aligned 订单号
    th.collapsing.center.aligned 代付金额
    th.collapsing.center.aligned 确认
    th.center.aligned 备 注

block tbody
  each record in records
    - var tr_color = ''
    case record.status
      when 1
        - tr_color = 'warning'
      when 2
        - tr_color = 'positive'
      when 3
        - tr_color = 'error'
      when 4
        - tr_color = ''
      when 5
        - tr_color = 'warning'
      default
        - tr_color = 'error'

    tr(class="#{tr_color}")
      td.collapsing.center.aligned= record.serial
      td.collapsing.center.aligned
        case record.status
          when 1
            i.icon.wait.orange.link(data-content="#{record.notes}"
              data-variation="small very wide")
          when 2
            i.icon.checkmark.yellow.link(data-content="#{record.notes}"
              data-variation="small very wide")
          when 3
            i.icon.remove.pink.link(data-content="#{record.notes}"
              data-variation="small very wide")
          when 4
            i.icon.checkmark.green.link(data-content="#{record.notes}"
              data-variation="small very wide")
          when 5
            i.icon.arrow.right.blue.link(data-content="#{record.notes}"
              data-variation="small very wide")
          default
            i.icon.question.red
      td.collapsing.center.aligned= record.sys_time.format('MM-DD HH:mm:ss')
      td.collapsing.center.aligned
        i.icon.send.outline.blue.link.trlist(data-content="查看消费交易流水"
          data-variation="small"
          data-keyword="#{record.t20_uuid}")
        = record.t20_info[0]
      td.collapsing.center.aligned= record.t20_info[1]
      td.collapsing.center.aligned= record.t20_info[2]
      td.collapsing.center.aligned= fmtamt2(record.t20_info[3])
      td.collapsing.center.aligned= fmtamt(record.p1_fee)
      if record.t40_info
        td.collapsing.left.aligned
          i.icon.send.outline.link.trlist(
            class="#{record.recover ? 'brown' : 'blue'}"
            data-content="查看代付交易流水"
            data-variation="small"
            data-keyword="#{record.t40_uuid}")
          = record.t40_info[0]
        td.collapsing.center.aligned= record.t40_info[2]
        td.collapsing.center.aligned= fmtamt2(record.t40_info[3])
        td.collapsing.center.aligned
          if record.t40_confirm
            i.icon.checkmark
        if record.t40_notes && record.t40_notes.length > 50
          td.center.aligned(data-content="#{record.t40_notes}"
            data-variation="small very wide")
            = record.t40_notes.substring(0,8)
        else
          td.center.aligned= record.t40_notes
      else
        td.center.aligned(colspan="5")
          if record.received
            | 未发送实时代付交易
          else
            | 未收到消费代付交易

      td.collapsing.center.aligned
        if record.recover
          i.icon.arrow.right.link.brown(
            data-content="查看追付记录" data-variation="small wide"
            onclick="window.location='/t40_recvr/done?" +
              "keyword=#{record.recvr_uuid}" +
              "&start_date=#{start_date}&end_date=#{end_date}'")
          if record.t40_uuid_old
            i.icon.send.outline.link.blue(
              data-content="查看原代付交易流水" data-variation="small wide"
              onclick="window.location='/trlist?" +
                "keyword=#{record.t40_uuid_old}" +
                "&start_date=#{start_date}&end_date=#{end_date}'")
          else
            i.icon.send.outline.grey.link.disabled(
              data-content="原代付交易流水为空" data-variation="small wide")
  else
      td.center.aligned.warning(colspan="14") 无数据
